local skel = fk.CreateSkill{
  name = "kqf__mouzhu",
}

Fk:loadTranslationTable{
  ["kqf__mouzhu"] = "谋诛",
  [":kqf__mouzhu"] = "出牌阶段开始时，你可与一名未横置角色拼点，赢的角色可对没赢的角色使用任意张【杀】。当你重置时，失去“谋诛”。",

  ["#kqf__mouzhu_ask"] = "谋诛：你可与一名未横置角色拼点，赢的角色可对没赢的角色使用任意张【杀】",
  ["#kqf__mouzhu_ask2"] = "对 %src 使用任意张【杀】",

  ["$kqf__mouzhu1"] = "刘董同气连枝，一损则俱损。",
  ["$kqf__mouzhu2"] = "妾虽女流，然亦有忠侍陛下之心。",
}


skel:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player.phase == Player.Play and
      table.find(target.room:getOtherPlayers(target, false), function (p)
        return player:canPindian(p) and not p.chained
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return player:canPindian(p) and not p.chained
    end)
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#kqf__mouzhu_ask",
      skill_name = skel.name,
    })
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self)
    local pindian = player:pindian({to}, skel.name)
    local win
    if pindian.results[to].winner == player then
        win = player
    elseif pindian.results[to].winner == to then
        win = to
        to = player
    end
    if win then
      while 1 do
        if to.dead then break end
        local use = room:askToUseCard(win, {
            prompt = "#kqf__mouzhu_ask2:" .. to.id,
            skill_name = skel.name,
            pattern = "slash",
            cancelable = true,
            extra_data = {
                exclusive_targets = {to.id},
                bypass_distances = true,
                bypass_times = true,
            },
        })
        if use then
            room:useCard(use)
        else
            break
        end
      end
    end
  end,
})

skel:addEffect(fk.ChainStateChanged, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and not player.chained
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "-"..skel.name)
  end,
})

return skel